package com.jghz.configure;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.bstek.bdf2.core.orm.DataSourceRegister;

@Configuration
public class DataSourceConfiguration {

	@Bean(name = "dataSource1")
	@Primary
	@ConfigurationProperties(prefix = "spring.datasource1")
	public DataSource DataSource1() {
		return DataSourceBuilder.create().build();
	}

	@Bean(name = "dataSource2")
	@ConfigurationProperties(prefix = "spring.datasource2")
	public DataSource DataSource2() {
		return DataSourceBuilder.create().build();
	}

	@Bean
	public DataSourceRegister registerNew() {
		DataSourceRegister dsr = new DataSourceRegister();
		dsr.setAsDefault(true);
		dsr.setDataSource(DataSource1());
		dsr.setName("ayxzNew");
		return dsr;
	}

}
